package com.study.ming.studydemo.thd;

class ThreadAA extends Thread {
    public ThreadAA() {
    }

    public ThreadAA(Object lock) {
        this.lock = lock;
    }

    private Object lock;

    public void run() {
        synchronized (lock) {
            for (int i = 0; i < 500; i++) {
                System.out.println(i + "AA");
            }
        }
//        try {
//            TimeUnit.SECONDS.sleep(15);
//            for (int i = 0; i < 200; i++) {
//                System.out.println(i+" AA");
//            }
//        }
//        catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("a结束");
    }
}

class ThreadBB extends Thread {
    public ThreadBB() {
    }

    public ThreadBB(Object lock) {
        this.lock = lock;
    }

    private Object lock;

    public void run() {
        synchronized (lock) {
            try {
//                Thread.sleep(1000);
                lock.wait(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 500; i++) {
                System.out.println(i + "BB++++");
            }
        }
        System.out.println("b结束");
    }
}

public class WaitTimeoutTest {
    public static void main(String[] args) {
        final Object lock = new Object();
        ThreadBB b = new ThreadBB(lock);
        ThreadAA a = new ThreadAA(lock);
        a.start();
        b.start();
    }
}